from selenium import webdriver
from time import sleep

from selenium.webdriver.common.by import By

#多元素定位
driver= webdriver.Firefox()
sleep(2)
driver.get("http://baidu.com")
sleep(2)
# elements = driver.find_elements(By.TAG_NAME,"input")
# print(type(elements))
# print(elements)
# for e in elements:
#     if e.get_attribute("id")=="kw" :
#         e.send_keys("hello")
#     # print(e.get_attribute("type"))
#     # print(e.get_attribute("name"))
# sleep(2)

from selenium.webdriver import ActionChains
# #双击
element = driver.find_element(By.CSS_SELECTOR,"#kw")
#多个动作连续操作
ActionChains(driver).send_keys_to_element(element,"hello").click(element).perform()
sleep(2)
# ActionChains(driver).double_click(element).perform()
# sleep(2)
# ActionChains(driver).context_click(element).perform()
# sleep(2)
# element = driver.find_element(By.XPATH,"/html/body/div[1]/div[1]/div[2]/a[2]")
# ActionChains(driver).move_to_element(element).perform()
# sleep(2)

#键盘操作
from selenium.webdriver import Keys
element = driver.find_element(By.CSS_SELECTOR,"#kw")
element.send_keys(Keys.CONTROL,'a')
sleep(2)
element.send_keys(Keys.CONTROL,'c')
sleep(2)
element.send_keys(Keys.BACK_SPACE)
sleep(2)
element.send_keys(Keys.CONTROL,'v')
sleep(2)
driver.quit()